package com.atguigu.gmall.mq.receiver;

import com.atguigu.gmall.mq.config.DeadLetterMqConfig;
import com.atguigu.gmall.mq.config.DelayMqConfig;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Date;

/**
 * @Author: 李旭
 * @Time: 15:45
 * @Description:
 */
@Component
public class DelayMessage {

    //基于插件延迟消息
    @RabbitListener(queues = DelayMqConfig.queue_delay_1)
    public void message(String msg, Message message, Channel channel) {
        try {

            System.out.println("接收到的消息：" + msg);
            System.out.println("接收到的消息时间：" + new Date());

            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
